//
//  MBHUDHelper.swift
//  MBHUDHelperDemo
//
//  Created by ysk on 2017/5/4.
//  Copyright © 2017年 ysk. All rights reserved.
//

import UIKit
import MBProgressHUD

public class MBHUDHelper: NSObject {
    static var hudView: MBProgressHUD?
    override init() {
        super.init()
    }
    
    public static func showToast(_ toastString: String) -> Void {
        let window = UIApplication.shared.windows.first
        let hud = MBProgressHUD.showAdded(to: window!, animated: true)
        hud.label.text = toastString
        hud.mode = .text
        hud.margin = 12.0
        hud.bezelView.color = UIColor(white: 0, alpha: 0.6)
        hud.isUserInteractionEnabled = false
        hud.hide(animated: true, afterDelay: 2.0)
    }
    
    public static func showLoadingInWindow(_ message: String = String()) -> Void {
        hudView?.hide(animated: false)
        let window = UIApplication.shared.windows.first!
        showLoadingInView(window, message: message)
    }
    public static func showLoadingInView(_ parentView: UIView, message: String = String()) -> Void {
        hudView?.hide(animated: false)
        hudView = MBProgressHUD.showAdded(to: parentView, animated: true)
        hudView?.mode = .indeterminate
        hudView?.label.text = message
        hudView?.margin = 18.0
        hudView?.bezelView.color = UIColor(white: 0, alpha: 0.60)
        hudView?.backgroundColor = UIColor(white: 0, alpha: 0.35)
        hudView?.contentColor = UIColor.green
        hudView?.minShowTime = 0.3
        hudView?.show(animated: true)
    }
    
    public static func hideHUDView() -> Void {
        hudView?.hide(animated: true)
    }
}
